<?php


namespace App\Http\Controllers\Internal;


use App\Models\Tag;

class TagController extends Controller
{
    public function index()
    {
        $this->validate($this->request, [
            'tagIds' => 'required|array'
        ]);
        $tagIds = $this->request->input('tagIds');
        $tagsObj = Tag::whereIn('id', $tagIds)->get();
        $items = [];
        /** @var Tag $tagObj */
        foreach ($tagsObj as $tagObj) {
            $coverUrl = $tagObj->cover()->value('uri');
            if ($coverUrl) {
                $coverUrl .= '?x-oss-process=style/tag';
            }
            $items[] = [
                'id' => $tagObj->getId(),
                'cn' => $tagObj->getCnName(),
                'en' => $tagObj->getEnName(),
                'audio' => $tagObj->audio()->value('uri'),
                'cover' => $coverUrl,
            ];
        }
        return $this->sendSuccessJson($items);
    }
}
